<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title id="title"></title>
    {load href="/static/admin/layui/js/jquery-3.3.1.min.js" /}
    {load href="/static/admin/layui/layui.js" /}
    {load href="/static/admin/layui/css/layui.css" /}
</head>
<body style="width:1200px;margin:50px auto;">

<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">推广后台</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a href="/login/Show/index">推广记录</a></li>
            <li class="layui-nav-item"><a href="/login/Registered/index">注册记录</a></li>
            <li class="layui-nav-item"><a href="/login/Statistics/index">推广统计</a></li>
            <li class="layui-nav-item"><a href="/login/Identification/index">标识码</a></li>
            <li class="layui-nav-item"><a href="/login/Ip/index">IP黑名单</a></li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    <span id="username"></span>
                </a>
                <!--<dl class="layui-nav-child">-->
                    <!--<dd><a href="">修改密码</a></dd>-->
                <!--</dl>-->
            </li>
            <li class="layui-nav-item"><a href="javascript:showTime()">退出</a></li>
        </ul>
    </div>

<!--    <div class="layui-footer">-->
<!--        &lt;!&ndash; 底部固定区域 &ndash;&gt;-->
<!--        © layui.com - 底部固定区域-->
<!--    </div>-->
</div>
{block name="main"}{/block}
<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use(['element','form'], function(){
        var element = layui.element;
        var form = layui.form;
        // 获取本地缓存中的token
        var tokenValue = layui.data('cache');
        if(tokenValue.token !== 'undefined'){
            $.ajax({
                url:"/api/v1.Token/verifyToken",
                // data:{"token":tokenValue.token},
                headers:{"token":tokenValue.token},
                type:"post",
                dataType:"json",
                success:function(res){
                    // 200则token不失效
                    if(res.code == 200){
                        var token = layui.data('cache')
                        $.ajax({
                            url:"/login/Show/getUserData",
                            type:"post",
                            headers:{"token":token.token},
                            dataType:"json",
                            success:function (res) {
                                $('#title').html(res.name + '推广详情页面')
                                $('#username').html(res.name)
                                data = res.sign
                                for(var key in data){
                                    $("#signData").append("<option value='" + data[key] + "'>" + data[key] + "</option>");
                                }
                                form.render('select');
                            }
                        })
                    }
                    // 404则token失效
                    if(res.code == 404 || res.code == 401){
                        window.location.href = "/login/Index/Timeout"
                    }
                },
                error:function(error){
                    console.log(error.responseJSON.code)
                    if(error.responseJSON.code == 401){
                        window.location.href = "/login/Index/Timeout"
                    }
                }
            })
        }
    });

    function showTime(){
        layui.use(['element','form'], function(){
            var tokenValue = layui.data('cache');
            if(tokenValue.token){
                layui.data('cache', {
                    key: 'token'
                    ,remove: true
                });
            }
            location.reload();
        })
    }
</script>

</body>
</html>
